﻿using System;
using System.Windows.Input;
using ClientOverflow.DataTransferObjects;

namespace ClientOverflow.ViewModels.QuestionViewViewModels
{
    /// <summary>
    /// ChooseAnswerCommand is a command in charge of updating the correct answer for a question.
    /// </summary>
    internal class ChooseAnswerCommand : ICommand
    {
        private readonly Answer answer;
        public event Action Executed = () => { };

        public ChooseAnswerCommand(Answer answer)
        {
            this.answer = answer;
        }

        public void Execute(object parameter)
        {
            using (var serviceClient = ServicesFactory.CreateClientOverflowServiceClient())
            {
                serviceClient.ChooseAnswer(answer.Question, answer);
            }

            Executed();
        }

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public event EventHandler CanExecuteChanged;
    }
}